function LoginBox(doc, client, onlogin, onerror)
{
	var loginbox = doc.createElement('div');
	loginbox.className = "loginbox";

	var error = doc.createElement('span');
	loginbox.appendChild(error);

	var login = doc.createElement('div');
	login.className = "login";

	var username = doc.createElement('input');
	username.name = "username";
	username.type = "text";

	var password = doc.createElement('input');
	password.name = "password";
	password.type = "password";

	var loginButton = doc.createElement('input');
	loginButton.type = "button";
	loginButton.value = "login";
	
	login.appendChild(username);
	login.appendChild(password);
	login.appendChild(loginButton);

	var logout = doc.createElement('div');
	logout.className = "logout";

	var greeting = doc.createElement('span');

	var logoutButton = doc.createElement('input');
	logoutButton.type = "button";
	logoutButton.value = "logout";

    logout.appendChild(greeting);
	logout.appendChild(logoutButton);

	loginbox.appendChild(login);

	function onloginWrapper(username)
	{
		greeting.innerText = "Logged in as " + username;
	    loginbox.removeChild(login);
	    loginbox.appendChild(logout);

		error.innerText = "";
	
		onlogin(username);
	}
	
	function onerrorWrapper(err)
	{
		error.innerText = err;

		onerror(err);
	}

	loginButton.onclick = function() { client.login(username.value, password.value, onloginWrapper, onerrorWrapper); }; 
	logoutButton.onclick = function() { client.logout(onerrorWrapper); };

	this.onlogout = function()
	{
	    loginbox.removeChild(logout);
	    loginbox.appendChild(login);
		error.innerText = "";
	}
	
	this.element = loginbox;
}


